package com.yunhoo.sys.bean;

import com.yunhoo.cqq.util.FileUploadDownloadToolKit;
import java.util.HashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;

@ManagedBean(name = "handBookBean")
@ViewScoped
public class HandBookBean {

    private String pageUrl = "/images/handbook/ssfpayflow.png";
    private String page = "/welcome.xhtml";

    public void selectdUrl(String str) {
        pageUrl = "";
        page = "";
        System.out.println("str:" + str);
        if (str.equals("down")) {
            page = forUrl().get(str);
        } else {
            pageUrl = forUrl().get(str);
        }
    }

    public String login() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);//务必设置为false
        session.invalidate();
        return "/login.jsp";
    }

    public void downHandBook(String str) {
        System.out.println("str:" + str);
        String key = forUrl().get(str);
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ServletContext scontext = (ServletContext) facesContext.getExternalContext().getContext();
        String filePath = scontext.getRealPath(key);
        System.out.println("filePath:" + filePath);
        FileUploadDownloadToolKit.download(filePath);
    }

    public static Map<String, String> forUrl() {
        Map<String, String> url = new HashMap<String, String>();
        url.put("ssfpayflow", "/images/handbook/ssfpayflow.png");
        url.put("liucheng", "/images/handbook/liucheng.png");
        url.put("wtjUpdate", "/images/handbook/wtjUpdate.png");
        url.put("ytjUpdate", "/images/handbook/ytjUpdate.png");
        url.put("deleteBill", "/images/handbook/deleteBill.png");
        url.put("navigate", "/images/handbook/navigate.png");
        url.put("currency", "/images/handbook/currency.png");
        url.put("feeDept", "/images/handbook/feeDept.png");
        url.put("feeProj", "/images/handbook/feeProj.png");
        url.put("ysProj", "/images/handbook/ysProj.png");
        url.put("expense", "/images/handbook/expense.jpg");
        url.put("loan", "/images/handbook/loan.png");
        url.put("travel", "/images/handbook/travel.jpg");
        url.put("abroad", "/images/handbook/abroad.jpg");
        url.put("pay", "/images/handbook/pay.png");
        url.put("app", "/images/handbook/app.png");
        url.put("down", "/downHandBook.xhtml");
        url.put("voucher", "/sysdoc/handbook/voucher.doc");
        url.put("book", "/sysdoc/handbook/book.doc");
        url.put("px", "/sysdoc/handbook/px.ppt");
        return url;
    }

    public String getPageUrl() {
        return pageUrl;
    }

    public void setPageUrl(String pageUrl) {
        this.pageUrl = pageUrl;
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }
}
